package com.hackaton.discounts;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class CategoriesActivity extends Activity {
	private ListView listView;
	private ArrayList<String> list;
	private ArrayAdapter<String> adapter;
	DatabaseManagerCategories db;
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.category);
        listView=(ListView)findViewById(R.id.listCategory);
        listView.setOnItemClickListener(new OnItemClickListener(){

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				
			}
        });
        list = getCategories();
        adapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_1, list);
        listView.setAdapter(adapter);
        
	}
	public ArrayList<String> getCategories(){
		ArrayList todoItems = new ArrayList();
		db = new DatabaseManagerCategories(this);
    	ArrayList<ArrayList<Object>> data = db.getAllRowsAsArrays();
    	for (int position=0; position < data.size(); position++)
    	{
    		ArrayList<Object> row = data.get(position);
    		todoItems.add(row.get(1).toString());
    	}
		//todoItems.add("Home");
		return todoItems;
	}
}
